package
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.net.Responder;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;

	[SWF(height=80, width=400)]
	public class Main extends Sprite
	{
		private var gateWay:RemotingConnection;
		private var responder:Responder;
		private var txtInput:TextField;
		private var txtResult:TextField;
		private var lblInput:TextField;
		private var btn:CustomSimpleButton;
		private var btnLabel:TextField;

		public function Main()
		{
			init();
		}

		private function init():void
		{
			gateWay=new RemotingConnection("http://localhost:1718/Gateway.aspx");//创建连接对象
			lblInput=new TextField();
			lblInput.text="请输入参数：";
			lblInput.selectable=false;
			lblInput.autoSize=TextFieldAutoSize.RIGHT;
			addChild(lblInput);
			lblInput.height=20;
			lblInput.x=10;
			lblInput.y=10;
			addChild(lblInput);

			txtInput=new TextField();
			txtInput.border=true;
			txtInput.width=200;
			txtInput.height=20;
			txtInput.type=TextFieldType.INPUT;
			txtInput.text="菩提树下的杨过";
			txtInput.y=lblInput.y;
			txtInput.x=lblInput.x + lblInput.width + 5;
			addChild(txtInput);

			btn=new CustomSimpleButton(60, 20, " 调 用 ");
			addChild(btn);
			btn.y=txtInput.y;
			btn.x=txtInput.x + txtInput.width + 10;

			txtResult=new TextField();
			addChild(txtResult);
			txtResult.x=lblInput.x;
			txtResult.y=lblInput.y + lblInput.height + 10;
			txtResult.width=380;
			txtResult.autoSize=TextFieldAutoSize.CENTER;
			txtResult.textColor=0xff0000;
			btn.addEventListener(MouseEvent.CLICK, btnClick);
		}

		private function btnClick(e:MouseEvent):void
		{
			gateWay.call("ServiceLib.TestLib.HelloWorld", new Responder(onResult, onFault), txtInput.text);//调用方法
			btn.enabled=false;
			btn.mouseEnabled=false;
		}

		//成功的回调函数
		private function onResult(result:String):void
		{
			//trace("成功：",result);//成功： hello , 菩提树下的杨过 , welcome to FluroineFx !
			txtResult.text=result;
			btn.enabled=true;
			btn.mouseEnabled=true;
		}

		//失败的回调函数
		private function onFault(result:String):void
		{
			//trace("失败：",result);
			txtResult.text=result;
			btn.enabled=true;
			btn.mouseEnabled=true;
		}
	}
}